package com.sromku.simple.fb.example;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.example.hal.model.Activite;
import com.example.hal.model.ActiviteController;

public class ActiviteAddActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.add_activite);

	Button btn = (Button) findViewById(R.id.addActiviteNow);
	btn.setOnClickListener(new OnClickListener() {

	    @Override
	    public void onClick(View v) {
			addActivite();
	    }
	});
    }

    final void addActivite()
    {
	final Thread checkUpdate = new Thread() {
	    public void run() {
		EditText nom = (EditText) findViewById(R.id.activiteNom);
		EditText logo = (EditText) findViewById(R.id.activiteLogo);
		Activite u = new Activite();
		u.setNom(nom.getText().toString());
		u.setLogo(logo.getText().toString());
		final ActiviteController uc = new ActiviteController();
		try {
		    uc.create(u);
		} catch (Exception e) {
		    return;
		}
		final Intent intent = new Intent(ActiviteAddActivity.this,
				MainActivity.class);
		startActivity(intent);
	    }
	};
	checkUpdate.start();
    }
}